﻿
function Popup_LoadInfo()
{
	// 获取Tab的相关信息
	chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
		console.log();
		var tab = tabs[0];
		$("#title").val(tab.title);
		$("#url").val(tab.url);
		$("#saveimg").attr("src", tab.favIconUrl);
		$("#saveimg2").attr("src", tab.favIconUrl);
	});
}

function Popup_SaveSuperMark()
{
	// { \"No\":6 , \"Type\":1 , \"Key\":\"wzy\" , \"Title\":\"我的个人主页\", \"URL\":\"alwaysking.cn\" , \"Img\":\"\", \"Time\":\"abc\"}
    LoadStroage_SuperMark(function(data, conetxt){
		
	var obj = {};
	var success = true;
	obj.No = HelpTool_GUID();
	obj.Type = 1;
	obj.Time = "";
	obj.Key = $("#mark").val();
	obj.Title = $("#title").val();
	obj.URL = $("#url").val();
	obj.Img = $("#saveimg").attr("src"); 
	
	if(obj.Key.length == 0){
		$("#mark").css({"background-color":"#ffb595"});
		success = false;
	}		
	if(obj.URL.length == 0){
		$("#url").css({"color":"#ffb595"});	
		success = false;
	}
	
	if(success == false){
			return;
	}
	
	data.list.unshift(obj);
	SaveStroage_SuperMark(data, Popup_SaveFinish);
		
	});
}

function Popup_SaveQuickStart()
{
	// { \"No\":6 , \"Type\":1 , \"Key\":\"wzy\" , \"Title\":\"我的个人主页\", \"URL\":\"alwaysking.cn\" , \"Img\":\"\", \"Time\":\"abc\"}
    LoadStroage_QuickStart(function(data, conetxt){
		
	var obj = {};
	obj.No = data.length;
	obj.URL = $("#url").val();
	obj.Title = $("#title").val();
	obj.Img = $("#saveimg").attr("src"); 
	
	data.unshift(obj);
	SaveStroage_QuickStart(data, Popup_SaveFinish);		
	});
}

function Popup_SaveFinish(err)
{
	window.close();	
}

$(function(){
	
	// 加载相关信息
	setTimeout(Popup_LoadInfo,300);
	
	// 初始化导航菜单
	$("#supermarkbutton").click(function(){
		$("#menubox").hide();
		$("#supermarkbox").show();
	});
	
	$("#Quickstartbutton").click(function(){
		$("#menubox").hide();
		$("#Quickstartbox").show();
	});
	
	
	// 初始化SuperMark
	$("#save").click(Popup_SaveSuperMark);
	$("#save").mouseover(function(e){
		$("#save").css({"background":"#32d296"});
	});
	
	$("#save").mouseout(function(e){
		$("#save").css({"background":"#ffffff"});
	});
	
	// 初始化QuickStart
	$("#save2").click(Popup_SaveQuickStart);
	$("#save2").mouseover(function(e){
		$("#save2").css({"background":"#32d296"});
	});
	
	$("#save2").mouseout(function(e){
		$("#save2").css({"background":"#ffffff"});
	});
}
);